@extends('layouts.admin')

@section('styles')
parent
{{ HTML::style('css/jquery-ui.min.css') }}
@stop

@section('content')
<div class="page-header">
	<h2>Category - 
		<small>
		@if($method == 'post')
			Add a new category
		@elseif($method == 'delete')
			Delete {{ $category->name }} category (Include all sub category) ?
		@else
			Edit {{ $category->name }} category
		@endif
		</small>
	</h2>
</div>
@if ($message = $errors->first('message'))
<div class="row">
	<div class="col-lg-12">
		<div class="alert alert-danger alert-block">
			<button type="button" class="close" data-dismiss="alert">&times;</button>
			<h4>Unsuccess</h4>
			{{{ $message }}}
		</div>
	</div>
</div>
@endif

<div class="row">
	<div class="col-lg-12">
		{{Form::model($category, array('method' => $method, 'url'=>'category/'.$category->id, 'class' => 'form-horizontal'))}}
		@unless($method == 'delete')
			<!-- Short Department Name -->
			<div class="form-group {{{ $errors->has('name') ? ' has-error' : '' }}}">
				<div class="col-sm-4">
					{{ Form::label('name', 'Category Name', array('class' => 'control-label')) }}
					{{ Form::text('name', Input::old('name'), array('class' => 'form-control')) }}
				</div>
			</div>

			<!-- Department Name -->
			<div class="form-group {{{ $errors->has('parent_name') ? ' has-error' : '' }}}">
				<div class="col-sm-4">
					{{ Form::label('parent_name', 'Category Parent Name', array('class' => 'control-label')) }}
					{{ Form::text('parent_name', Input::old('parent_name') == null ? $categoryParent->name : Input::old('parent_name'), array('class' => 'form-control typeahead')) }}
				</div>
			</div>
			
			<div class="form-group">
				<div class="col-sm-4">
					{{Form::submit("Save", array("class"=>"btn btn-success"))}}
					<a href="{{url('category')}}" class="btn btn-default">
						Cancel
					</a>
				</div>
			</div>
		@else
			<div class="form-group">
				<div class="col-sm-4">
					{{Form::submit("Delete", array("class"=>"btn btn-success"))}}
					<a href="{{url('category')}}" class="btn btn-default">
						Cancel
					</a>
				</div>
			</div>
		@endif
		{{Form::close()}}
	</div>
</div>
@stop

@section('endscript')
@parent
{{ HTML::script('js/jquery-ui.min.js') }}
<script type="text/javascript">
$(function() {
    var availableTags = [{{ $category_options }}];
    $( "#parent_name" ).autocomplete({
      source: availableTags
    });
  });
</script>
@stop

